//
//  CCRSMSViewModel.m
//  Activity
//
//  Created by its on 15/5/8.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCRSMSViewModel.h"
#import <AVOSCloud/AVOSCloud.h>
@implementation CCRSMSViewModel

- (id) initWithPhone:(NSString *)phone {
  if (self = [super init]) {
    _phone = phone;
    _tick = 60;
  }
  return self;
}

- (RACSignal *) verfitySMSCode:(NSString *) code {
  return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [AVUser signUpOrLoginWithMobilePhoneNumberInBackground:self.phone smsCode:code block:^(AVUser *user, NSError *error) {
      if (error) {
        [subscriber sendError: error];
      } else {
        [subscriber sendNext:user];
      }
      [subscriber sendCompleted];
    }];
    return [RACDisposable disposableWithBlock:^{
      
    }];
  }];
}

- (RACSignal *) resendSMSCode {
  return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [AVOSCloud requestSmsCodeWithPhoneNumber:self.phone callback:^(BOOL succeeded, NSError *error) {
      
    }];
    return [RACDisposable disposableWithBlock:^{
      
    }];
  }];
}
@end
